package com.itheima.spring;

import net.sf.cglib.proxy.Enhancer;
import net.sf.cglib.proxy.MethodInterceptor;
import net.sf.cglib.proxy.MethodProxy;
import org.junit.Test;

import java.lang.reflect.Method;

/**
 * @Description：
 */
public class Customer {


    @Test
    public void needHouse(){
        System.out.println("=====================");
        //代理模式下的租房
        HouseOwner houseOwnerProxy = (HouseOwner) Enhancer.create(HouseOwner.class,
                new MethodInterceptor() {
                    @Override
                    public Object intercept(Object o, Method method,
                                            Object[] objects, MethodProxy methodProxy) throws Throwable {
                        //增强
                        System.out.println("中介小王：带你看房子");
                        //返回结果
                        return  methodProxy.invokeSuper(o, objects);
                    }
                });

        houseOwnerProxy.rentingHouse();
    }
}